package cn.tinkerpatch.com.tinker;

import android.content.Context;

import com.tencent.tinker.lib.tinker.Tinker;
import com.tencent.tinker.lib.tinker.TinkerInstaller;
import com.tencent.tinker.loader.app.ApplicationLike;

/**
 * Created by admin
 * 2018/10/4.
 * content
 */

public class TinkerManager {
    private static boolean isInstalled = false;

    private static ApplicationLike mAppLike;

    /**
     * 完成 Tinker的初始化
     * @param applicationLike
     */
    public static void installTinker(ApplicationLike applicationLike) {
        mAppLike = applicationLike;
        if (isInstalled) {
            return;
        }
        TinkerInstaller.install(mAppLike);//完成 tinker 初始化
        isInstalled=true;
    }

    public static void loadPath(String path){
        if(Tinker.isTinkerInstalled()){
            TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(),path);
        }
    }

    //通过 ApplicationLike 获取 Context
    private static Context getApplicationContext(){
        if(mAppLike!=null){
            return mAppLike.getApplication().getApplicationContext();
        }
        return null;
    }

}
